/* 自身头文件 */
#include "cpevendorhuawei.h"
#include "cpepluginmanager.h"
#include "ui_cpevendorhuawei.h"
#include "cpebar.h"
/* 来自CpeManager的其他头文件 */
#include "../CpeVendorManager/icpevendormanager.h"
#include "../CpeConfig/icpeconfig.h"
#include "../CpeNet/icpenet.h"
#include "../CpeMainUI/icpemainui.h"
#include "../CpeUtil/icpeutil.h"
#include "../CpeForceUI/icpeforceui.h"
#include "../CpeLogUI/icpelogui.h"
#include "../CpeLoginUI/icpeloginui.h"
/* Qt头文件 */
#include <QTimer>

CpeVendorHUAWEI::CpeVendorHUAWEI()
    : ui(new Ui::CpeVendorHUAWEI)
    , m_bNrOption(false)
    , m_timer(nullptr)
    , m_bNoScs(false)
{
    ui->setupUi(this);
#ifdef Q_OS_ANDROID
    ui->rdoAuto->setStyleSheet("QRadioButton::indicator {width: 18px; height: 18px;}");
    ui->rdoExternal->setStyleSheet("QRadioButton::indicator {width: 18px; height: 18px;}");
    ui->rdoInternal->setStyleSheet("QRadioButton::indicator {width: 18px; height: 18px;}");
    ui->rdoMixed->setStyleSheet("QRadioButton::indicator {width: 18px; height: 18px;}");
    ui->chk5GAntenna->setStyleSheet("QCheckBox::indicator {width: 18px; height: 18px;}");
    ui->chkDataSwitch->setStyleSheet("QCheckBox::indicator {width: 18px; height: 18px;}");

#endif
    //Windows默认字号修改
#ifdef Q_OS_WIN
    QFont font = this->font();
    font.setPointSize(10);
    this->setFont(font);
#endif
    //向主窗口中插入登录设置控件
    if (getInterface(LoginUI))
    {
        getInterface(LoginUI)->insertLoginSettings("华为", CPE_LOGIN_INPUT_IP);
        //getInterface(LoginUI)->insertLoginSettings("华为", CPE_LOGIN_INPUT_USER);
        getInterface(LoginUI)->insertLoginSettings("华为", CPE_LOGIN_INPUT_PASSWORD);
    }

    //初始化所有进度条控件
    ui->barRSRP->init(-128, -75, -115, -105, -95, -85, "dBm", false, false);
    ui->barNRRSRP->init(-128, -75, -115, -105, -95, -85, "dBm", false, false);
    ui->barRSRQ->init(-30, 0, -20, -15, -10, -6, "dB", false, false);
    ui->barNRRSRQ->init(-30, 0, -20, -15, -10, -6, "dB", false, false);
    ui->barSINR->init(-15, 30, 3, 10, 15, 22, "dB", false, false);
    ui->barNRSINR->init(-15, 30, 3, 10, 15, 22, "dB", false, false);
    ui->barCQI->init(0, 15, 4, 7, 10, 13, "", false, false);
    ui->barDLMCS->init(0, 28, 0, 0, 0, 0, "", false, true);
    ui->barULMCS->init(0, 28, 0, 0, 0, 0, "", false, true);
    ui->barNRDLMCS->init(0, 28, 0, 0, 0, 0, "", false, true);
    ui->barNRULMCS->init(0, 28, 0, 0, 0, 0, "", false, true);
    ui->barPUCCH->init(-44, 23, 0, 5, 10, 20, "dBm", true, false);
    ui->barPUSCH->init(-44, 23, 0, 5, 10, 20, "dBm", true, false);
    ui->barNRPUSCH->init(-50, 23, 0, 5, 10, 20, "dBm", true, false);
    ui->barNRPUCCH->init(-50, 23, 0, 5, 10, 20, "dBm", true, false);
    ui->barBattery->init(0, 100, 20, 40, 60, 80, "%", false, false);
    ui->barDLBW->init(0, 20, 0, 0, 0, 0, "MHz", false, true);
    ui->barULBW->init(0, 20, 0, 0, 0, 0, "MHz", false, true);
    ui->barNRDLBW->init(0, 100, 0, 0, 0, 0, "MHz", false, true);
    ui->barNRULBW->init(0, 100, 0, 0, 0, 0, "MHz", false, true);
    connect(this, &CpeVendorHUAWEI::cycleSignal, this, &CpeVendorHUAWEI::onCycle);
    connect(&m_timer, &QTimer::timeout, this, [ = ]()
    {
        emit cycleSignal();
    });
}

void CpeVendorHUAWEI::startPlugin()
{
}

void CpeVendorHUAWEI::recognize()
{
    if (getInterface(Config))
    {
        //读取本厂家的登录设置
        m_strIP = getInterface(Config)->getProperty("华为", CPE_LOGIN_INPUT_IP);
        if (m_strIP.isEmpty())
        {
            return;
        }
        m_strUser = "admin";
        m_strPass = getInterface(Config)->getProperty("华为", CPE_LOGIN_INPUT_PASSWORD);
        m_strIP = m_strIP.contains("http") ? m_strIP : "http://" + m_strIP;
        get("CpeVendorHUAWEI", CPE_HUAWEI_RECOGNIZE, "/");
    }

}

void CpeVendorHUAWEI::recMsgfromManager(PluginMetaData metadata)
{
    if (getInterface(Util) == nullptr || getInterface(MainUI) == nullptr)
    {
        return;
    }
    //返回的header里若有下回post的token，要存一下
    if (!metadata.spMapHeader->isEmpty())
    {
        if (metadata.spMapHeader->contains("__RequestVerificationToken"))
        {
            m_strToken = metadata.spMapHeader->value("__RequestVerificationToken");
            if (m_strToken.contains("#"))
            {
                m_strToken = m_strToken.left(m_strToken.indexOf("#"));
            }
        }
    }
    QString str = metadata.strMsg;
    str.remove("&gt;=");
    str.remove("&amp;lt;=");
    str.remove("&amp;gt;=");
    str.remove("&lt;");
    switch (metadata.iType)
    {
        case CPE_HUAWEI_RECOGNIZE:
            {
                if (str.isEmpty() || str.contains("no_connect") || !str.contains("token"))
                {
                    if (getInterface(LogUI))
                    {
                        LOG_WARNING("CpeVendorHUAWEI", "不是华为设备！");
                    }
                    break;
                }
                if (getInterface(LogUI))
                {
                    LOG_INFO("CpeVendorHUAWEI", "是华为设备，开始登录...");
                }
                //试探结果：是华为的CPE，将本UI插到CpeMainUI中
                if (getInterface(VendorManager))
                {
                    getInterface(VendorManager)->setVendor("CpeVendorHUAWEI");
                }
                getInterface(MainUI)->addTab(this, "华为", true);
                if (getInterface(ForceUI))
                {
                    //删除NR锁频段选项卡
                    getInterface(ForceUI)->hideNR();
                    //华为锁网和锁频用一个按钮，隐藏锁网按钮
                    getInterface(ForceUI)->hideLockRatBtn();
                }
                get("CpeVendorHUAWEI", CPE_HUAWEI_LOGINSTATE, "api/user/state-login");
                break;
            }
        case CPE_HUAWEI_GETTOKEN:
            {
                m_strToken = getInterface(Util)->getXml(str, "TokInfo");
                postHelper();
                break;
            }
        case CPE_HUAWEI_LOGINSTATE:
            {
                if (getInterface(Util)->getXml(str, "lockstatus") == "1")
                {
                    getInterface(MainUI)->updateMessage("你的账户被锁定！剩余时间：" + getInterface(Util)->getXml(str, "remainwaittime") + "秒。");
                    getInterface(MainUI)->uncheckAutoRefresh();
                    break;
                }
                if (getInterface(Util)->getXml(str, "State") == "0")
                {
                    getInterface(MainUI)->updateMessage("已经登录了！厂家：华为。");
                    refreshOnce();
                    startCycle();
                }
                else
                {
                    if (str.contains("lockstatus"))  //SCRAM
                    {
                        post("CpeVendorHUAWEI", CPE_HUAWEI_CHALLENGELOGIN, "api/user/challenge_login", "<username>" + m_strUser + "</username><firstnonce>6b3807e2e9934bd79d69e0779f43bf2057921b2187224dbab1271b0002af8f4b</firstnonce><mode>1</mode>");
                    }
                    else
                    {
                        if (getInterface(Util)->getXml(str, "password_type") == "4")   //New
                        {
                            get("CpeVendorHUAWEI", CPE_HUAWEI_GETLOGINTOKEN, "api/webserver/SesTokInfo");
                        }
                        else    //Old
                        {
                        }
                    }
                }
                break;
            }
        case CPE_HUAWEI_CHALLENGELOGIN:
            {
                if (str.contains("code"))
                {
                    QString strCode = getInterface(Util)->getXml(str, "code");
                    if (strCode == "108007")
                    {
                        getInterface(MainUI)->updateMessage("登录失败！登录功能已被屏蔽，剩余时间：" + getInterface(Util)->getXml(str, "waittime") + "秒");
                    }
                    else if (strCode == "108005")
                    {
                        getInterface(MainUI)->updateMessage("登录失败！登录操作太频繁！");
                    }
                    else
                    {
                        getInterface(MainUI)->updateMessage("登录失败，错误号：" + getInterface(Util)->getXml(str, "code"));
                    }
                    getInterface(MainUI)->uncheckAutoRefresh();
                    break;
                }
                QString strServerNonce = getInterface(Util)->getXml(str, "servernonce");
                int iIterations = getInterface(Util)->getXml(str, "iterations").toInt();
                QString strSalt = getInterface(Util)->getXml(str, "salt");
                QString strPost = getInterface(Util)->getHWClientProof(m_strPass, strSalt, strServerNonce, iIterations);
                post("CpeVendorHUAWEI", CPE_HUAWEI_AUTHLOGIN, "/api/user/authentication_login", strPost);
                break;
            }
        case CPE_HUAWEI_AUTHLOGIN:
            {
                if (str.contains("serversignature"))
                {
                    getInterface(MainUI)->updateMessage("SCRAM登录成功！厂家：华为。");
                    refreshOnce();
                    startCycle();
                }
                else
                {
                    QString strCode = getInterface(Util)->getXml(str, "code");
                    if (strCode == "108006")
                    {
                        getInterface(MainUI)->updateMessage("登录失败已达" + getInterface(Util)->getXml(str, "count") + "次，还有" + getInterface(Util)->getXml(str, "remaincount") + "次机会，超限会被屏蔽" + getInterface(Util)->getXml(str, "tobelockedtime") + "分钟。");
                    }
                    else if (strCode == "108007")
                    {
                        getInterface(MainUI)->updateMessage("登录失败！登录功能已被屏蔽，剩余时间：" + getInterface(Util)->getXml(str, "waittime") + "秒");
                    }
                    else if (strCode == "108005")
                    {
                        getInterface(MainUI)->updateMessage("登录失败！登录操作太频繁！");
                    }
                    getInterface(MainUI)->uncheckAutoRefresh();
                }
                break;
            }
        case CPE_HUAWEI_GETLOGINTOKEN:
            {
                m_strToken = getInterface(Util)->getXml(str, "TokInfo");
                QString strPost = getInterface(Util)->getHWPassword(m_strUser, m_strPass, m_strToken);
                post("CpeVendorHUAWEI", CPE_HUAWEI_NEWLOGIN, "api/user/login", strPost);
                break;
            }
        case CPE_HUAWEI_NEWLOGIN:
            {
                if (str.contains("OK"))
                {
                    getInterface(MainUI)->updateMessage("新方式登录成功！厂家：华为。");
                    refreshOnce();
                    startCycle();
                }
                else
                {
                    QString strCode = getInterface(Util)->getXml(str, "code");
                    if (strCode == "108006")
                    {
                        getInterface(MainUI)->updateMessage("登录失败已达" + getInterface(Util)->getXml(str, "count") + "次，多次错误将被屏蔽登录一段时间！");
                    }
                    else if (strCode == "108007")
                    {
                        getInterface(MainUI)->updateMessage("登录失败！登录功能已被屏蔽，剩余时间：" + getInterface(Util)->getXml(str, "waittime") + "秒");
                    }
                    else if (strCode == "108005")
                    {
                        getInterface(MainUI)->updateMessage("登录失败！登录操作太频繁！");
                    }
                    else
                    {
                        getInterface(MainUI)->updateMessage("登录失败！错误号：" + getInterface(Util)->getXml(str, "code"));
                    }
                    getInterface(MainUI)->uncheckAutoRefresh();
                }
                break;
            }
        case CPE_HUAWEI_INFORMATION:
            {
                ui->txtHard->setText(getInterface(Util)->getXml(str, "DeviceName"));
                QString strSoftName = getInterface(Util)->getXml(str, "SoftwareVersion");
                if (strSoftName.contains("&#40;"))
                {
                    strSoftName = getInterface(Util)->strMid(strSoftName, "&#40;", "&#41;");
                }
                ui->txtSoft->setText(strSoftName);
                get("CpeVendorHUAWEI", CPE_HUAWEI_ANTENNA, "api/device/antenna_type");
                break;
            }
        case CPE_HUAWEI_ANTENNA:
            {
                QString ant1 = getInterface(Util)->getXml(str, "antenna1type");
                if (ant1 == "" && getInterface(Util)->getXml(str, "antennatype") != "")
                {
                    ant1 = getInterface(Util)->getXml(str, "antennatype");
                }
                QString ant2 = getInterface(Util)->getXml(str, "antenna2type");
                //              if (ant1 == "0" && ant2 == "0") {
                //                  runjs("$('#antennastatus').html(\"1内,2内\")");
                //              } else if (ant1 == "0" && ant2 == "1") {
                //                  runjs("$('#antennastatus').html(\"1内,2外\")");
                //              } else if (ant1 == "1" && ant2 == "0") {
                //                  runjs("$('#antennastatus').html(\"1外,2内\")");
                //              } else if (ant1 == "1" && ant2 == "1") {
                //                  runjs("$('#antennastatus').html(\"1外,2外\")");
                //              } else if (ant1 == "1" && ant2 == "") {
                //                  runjs("$('#antennastatus').html(\"外置\")");
                //              } else if (ant1 == "0" && ant2 == "") {
                //                  runjs("$('#antennastatus').html(\"内置\")");
                //              }
                //              if (str=="") {
                //                  runjs("$('#tbrssiant').css('display', 'none')");
                //                  runjs("$('#antennastatus').html('N/A')");
                //              }
                get("CpeVendorHUAWEI", CPE_HUAWEI_DATASWITCH, "api/dialup/mobile-dataswitch");
                break;
            }
        case CPE_HUAWEI_DATASWITCH:
            {
                if (getInterface(Util)->getXml(str, "dataswitch") == "1")
                {
                    ui->chkDataSwitch->setChecked(true);
                }
                else
                {
                    ui->chkDataSwitch->setChecked(false);
                }

                get("CpeVendorHUAWEI", CPE_HUAWEI_NETMODELIST, "api/net/net-mode-list");
                break;
            }
        case CPE_HUAWEI_NETMODELIST:   //硬件支持的频段返回
            {
                if (getInterface(ForceUI) == nullptr)
                {
                    break;
                }
                getInterface(ForceUI)->clearAllBandList();
                getInterface(ForceUI)->clearRatList();
                QString strTemp = getInterface(Util)->getXml(str, "BandList");
                while (strTemp.contains("<Value>"))
                {
                    QString strMask = getInterface(Util)->getXml(strTemp, "Value");
                    strTemp.remove("<Value>" + strMask + "</Value>");
                    if (strMask == "3fffffff")
                    {
                        break;
                    }
                    if (!strMask.startsWith("0x"))
                    {
                        strMask = "0x" + strMask;
                    }
                    getInterface(ForceUI)->insertBand(CPE_BANDTYPE_CGW, getInterface(Util)->strToBandList(strMask));
                }
                strTemp = getInterface(Util)->getXml(str, "AccessList");
                if (strTemp.contains("00"))
                {
                    getInterface(ForceUI)->insertRat("00", "Auto");
                }
                if (strTemp.contains("01"))
                {
                    getInterface(ForceUI)->insertRat("01", "GSM");
                }
                if (strTemp.contains("02"))
                {
                    getInterface(ForceUI)->insertRat("02", "3G");
                }
                if (strTemp.contains("03"))
                {
                    getInterface(ForceUI)->insertRat("03", "4G");
                }
                if (strTemp.contains("04") && strTemp.contains("07"))
                {
                    getInterface(ForceUI)->insertRat("0407", "EVDO/1x");
                }
                if (strTemp.contains("07"))
                {
                    getInterface(ForceUI)->insertRat("07", "EVDO");
                }
                if (strTemp.contains("04"))
                {
                    getInterface(ForceUI)->insertRat("04", "1x");
                }
                if (strTemp.contains("08"))
                {
                    getInterface(ForceUI)->insertRat("08", "NR");
                }
                strTemp = getInterface(Util)->getXml(str, "LTEBand");
                strTemp = getInterface(Util)->getXml(strTemp, "Value");
                if (!strTemp.startsWith("0x"))
                {
                    strTemp.push_front("0x");
                }
                getInterface(ForceUI)->insertBand(CPE_BANDTYPE_LTE, getInterface(Util)->strToBandList(strTemp));
                get("CpeVendorHUAWEI", CPE_HUAWEI_NETMODE, "api/net/net-mode");
                break;
            }
        case CPE_HUAWEI_NETMODE:   //当前的频段返回
            {
                if (getInterface(ForceUI) == nullptr)
                {
                    break;
                }
                if (str.contains("networkOption"))
                {
                    getInterface(ForceUI)->showNROption();
                }
                QString strMode = getInterface(Util)->getXml(str, "NetworkMode");
                getInterface(ForceUI)->checkRat(strMode);
                if (str.contains("networkOption"))
                {
                    QString strNROpt = getInterface(Util)->getXml(str, "networkOption");
                    getInterface(ForceUI)->checkNROption((CpeEmNRType)strNROpt.toInt());
                    m_bNrOption = true;
                }
                else
                {
                    getInterface(ForceUI)->hideNROption();
                    m_bNrOption = false;
                }
                QString strNetBand = getInterface(Util)->getXml(str, "NetworkBand");
                m_strCGW = strNetBand;
                QString strLTEBand = getInterface(Util)->getXml(str, "LTEBand");
                if (!strLTEBand.startsWith("0x"))
                {
                    strLTEBand.push_front("0x");
                }
                if (!strNetBand.startsWith("0x"))
                {
                    strNetBand.push_front("0x");
                }
                getInterface(ForceUI)->checkBand(CPE_BANDTYPE_LTE, getInterface(Util)->strToBandList(strLTEBand));
                getInterface(ForceUI)->checkBand(CPE_BANDTYPE_CGW, getInterface(Util)->strToBandList(strNetBand));
                get("CpeVendorHUAWEI", CPE_HUAWEI_LOCKFREQ, "api/net/lock-freq");
                //get("CpeVendorHUAWEI", CPE_HUAWEI_STATUS, "api/monitoring/status");
                break;
            }
        case CPE_HUAWEI_LOCKFREQ:
            {
                //只有鼎桥和新版CPE才有
                if (getInterface(ForceUI) == nullptr)
                {
                    break;
                }
                if (str.contains("freq"))
                {
                    QString strMode = getInterface(Util)->getXml(str, "mode");
                    QString strType = getInterface(Util)->getXml(str, "enable");
                    QString strARFCN = getInterface(Util)->getXml(str, "freq");
                    QString strPCI = getInterface(Util)->getXml(str, "cellid");
                    QString strBand = getInterface(Util)->getXml(str, "band");
                    QString strScs = getInterface(Util)->getXml(str, "scstype");
                    if (strScs == "")
                    {
                        m_bNoScs = true;
                        getInterface(ForceUI)->hideScs();
                    }
                    if (strType == "3" || strType == "0")
                    {
                        strARFCN = "";
                        strPCI = "";
                    }
                    if (strType == "1")
                    {
                        strPCI = "";
                    }
                    if (strMode == "0")
                    {
                        getInterface(ForceUI)->setNRLockCell("", "", "", "");
                        getInterface(ForceUI)->setLTELockCell(strARFCN, strPCI);
                    }
                    else if (strMode == "1")
                    {
                        getInterface(ForceUI)->setNRLockCell(strARFCN, strPCI, strBand, strScs);
                        getInterface(ForceUI)->setLTELockCell("", "");
                    }
                }
                else
                {
                    getInterface(ForceUI)->hideLockCell();
                }
                get("CpeVendorHUAWEI", CPE_HUAWEI_EXTNRANTENNA, "api/device/antenna_ext_td_switch");
                break;
            }
        case CPE_HUAWEI_EXTNRANTENNA:
            {
                if (!str.contains("extantennaswitch"))
                {
                    ui->lbl5GAntenna->hide();
                    ui->chk5GAntenna->hide();
                }
                QString strSwitch = getInterface(Util)->getXml(str, "extantennaswitch");
                if (strSwitch == "1")
                {
                    ui->chk5GAntenna->setChecked(true);
                }
                else
                {
                    ui->chk5GAntenna->setChecked(false);
                }
                get("CpeVendorHUAWEI", CPE_HUAWEI_EXTANTENNA, "api/device/antenna_set_type");
                break;
            }
        case CPE_HUAWEI_EXTANTENNA:
            {
                if (!str.contains("antennasettype"))
                {
                    ui->lblAntenna->hide();
                    hideLayout(ui->layoutAntenna);
                }
                QString strSwitch = getInterface(Util)->getXml(str, "antennasettype");
                if (strSwitch == "0")
                {
                    ui->rdoAuto->setChecked(true);
                }
                if (strSwitch == "1")
                {
                    ui->rdoExternal->setChecked(true);
                }
                if (strSwitch == "2")
                {
                    ui->rdoInternal->setChecked(true);
                }
                if (strSwitch == "3")
                {
                    ui->rdoMixed->setChecked(true);
                }
                break;
            }
        case CPE_HUAWEI_STATUS:
            {
                status(str);
                get("CpeVendorHUAWEI", CPE_HUAWEI_TRAFFIC, "api/monitoring/traffic-statistics");
                break;
            }
        case CPE_HUAWEI_TRAFFIC:
            {
                traffic(str);
                get("CpeVendorHUAWEI", CPE_HUAWEI_PLMN, "api/net/current-plmn");
                break;
            }
        case CPE_HUAWEI_PLMN:
            {
                plmn(str);
                get("CpeVendorHUAWEI", CPE_HUAWEI_CELLINFO, "api/net/cell-info");
                break;
            }
        case CPE_HUAWEI_CELLINFO:
            {
                cellInfo(str);
                get("CpeVendorHUAWEI", CPE_HUAWEI_SIGNAL, "api/device/signal");
                break;
            }
        case CPE_HUAWEI_SIGNAL:
            {
                signal(str);
                get("CpeVendorHUAWEI", CPE_HUAWEI_TRAFFICMONTH, "api/monitoring/month_statistics");
                break;
            }
        case CPE_HUAWEI_TRAFFICMONTH:
            {
                totalTraffic(str);
                m_mutex.unlock();
                break;
            }
        case CPE_HUAWEI_USER_POSTRETURN:
            {
                if (str.contains("code"))
                {
                    getInterface(MainUI)->updateMessage("操作失败，错误号：" + getInterface(Util)->getXml(str, "code"));
                }
                else
                {
                    getInterface(MainUI)->updateMessage("操作已成功！");
                    refreshOnce();
                }
                break;
            }
    }
}

void CpeVendorHUAWEI::logout()
{
    stopCycle();
    post("CpeVendorHUAWEI", CPE_HUAWEI_USER_LOGOUT, "api/user/logout", "<Logout>1</Logout>");
}

void CpeVendorHUAWEI::reboot()
{
    stopCycle();
    post("CpeVendorHUAWEI", CPE_HUAWEI_USER_POSTRETURN, "api/device/control", "<Control>1</Control>");
}

void CpeVendorHUAWEI::setBandLock(const std::vector<int> &vecCGW, const std::vector<int> &vecLTE, const std::vector<int> &vecNR, int iType)
{
    if (getInterface(ForceUI) && getInterface(Util))
    {
        QString strMode = getInterface(ForceUI)->getRat();
        QString strNROpt = QString::number(getInterface(ForceUI)->getNROption());
        QString strPost = "<NetworkMode>" + strMode + "</NetworkMode>" + "<NetworkBand>" + getInterface(Util)->bandListToHex(vecCGW) + "</NetworkBand>";
        strPost += "<LTEBand>" + getInterface(Util)->bandListToHex(vecLTE) + "</LTEBand>";
        if (iType != -1)
        {
            strPost += "<networkOption>" + strNROpt + "</networkOption>";
        }
        post("CpeVendorHUAWEI", CPE_HUAWEI_USER_POSTRETURN, "api/net/net-mode", strPost);
    }

}

void CpeVendorHUAWEI::setLTECellLock(const QString &strEARFCN, const QString &strPCI)
{
    if (strEARFCN == "")
    {
        getInterface(MainUI)->updateMessage("频点为必填项！");
        return;
    }
    QString strPost;

    if (strPCI == "")
    {
        //PCI没填，执行锁频点
        strPost = "<mode>0</mode><enable>1</enable><freq>" + strEARFCN + "</freq><band>" + QString::number(getInterface(Util)->arfcnToLTEBand(strEARFCN)) + "</band><cellid>0</cellid>";
    }
    else
    {
        //都填了，执行锁小区
        strPost = "<mode>0</mode><enable>2</enable><freq>" + strEARFCN + "</freq><band>" + QString::number(getInterface(Util)->arfcnToLTEBand(strEARFCN)) + "</band><cellid>" + strPCI + "</cellid>";
    }
    post("CpeVendorHUAWEI", CPE_HUAWEI_USER_POSTRETURN, "api/net/lock-freq", strPost);
}

void CpeVendorHUAWEI::setNRCellLock(const QString &strEARFCN, const QString &strPCI, const QString &strBand, const QString &strSCS)
{
    if (strBand == "")
    {
        getInterface(MainUI)->updateMessage("频段为必填项！");
        return;
    }
    if (!m_bNoScs && strSCS == "")
    {
        getInterface(MainUI)->updateMessage("SCS为必填项！");
        return;
    }
    QString strPost;
    if (strEARFCN == "")
    {
        //频点没填，是锁频段
        if (m_bNoScs)
        {
            strPost = "<mode>1</mode><enable>3</enable><freq>0</freq><band>" + strBand + "</band><cellid>0</cellid>";
        }
        else
        {
            strPost = "<mode>1</mode><enable>3</enable><scstype>" + strSCS + "</scstype><freq>0</freq><band>" + strBand + "</band><cellid>0</cellid>";
        }

    }
    else
    {
        if (strPCI == "")
        {
            //PCI没填，执行锁频点
            if (m_bNoScs)
            {
                strPost = "<mode>1</mode><enable>1</enable><freq>" + strEARFCN + "</freq><band>" + strBand + "</band><cellid>0</cellid>";
            }
            else
            {
                strPost = "<mode>1</mode><enable>1</enable><scstype>" + strSCS + "</scstype><freq>" + strEARFCN + "</freq><band>" + strBand + "</band><cellid>0</cellid>";
            }
        }
        else
        {
            //都填了，执行锁小区
            if (m_bNoScs)
            {
                strPost = "<mode>1</mode><enable>2</enable><freq>" + strEARFCN + "</freq><band>" + strBand + "</band><cellid>" + strPCI + "</cellid>";
            }
            else
            {
                strPost = "<mode>1</mode><enable>2</enable><scstype>" + strSCS + "</scstype><freq>" + strEARFCN + "</freq><band>" + strBand + "</band><cellid>" + strPCI + "</cellid>";
            }
        }
    }
    post("CpeVendorHUAWEI", CPE_HUAWEI_USER_POSTRETURN, "api/net/lock-freq", strPost);
}

void CpeVendorHUAWEI::onCycle()
{
    //自动刷新的执行顺序status->traffic->plmn->cellinfo->signal->trafficmonth
    if (m_mutex.tryLock())
    {
        get("CpeVendorHUAWEI", CPE_HUAWEI_STATUS, "api/monitoring/status");
    }
}

void CpeVendorHUAWEI::startCycle()
{
    m_timer.start(1000);
}

void CpeVendorHUAWEI::stopCycle()
{
    m_timer.stop();
    if (getInterface(MainUI))
    {
        getInterface(MainUI)->uncheckAutoRefresh();
    }
}

void CpeVendorHUAWEI::get(const QString &strPlugin, int iInfoID, const QString &strUrl)
{
    if (getInterface(Net))
    {
        QSharedPointer<QHash<QString, QString>> spMapHeader = QSharedPointer<QHash<QString, QString>>::create(QHash<QString, QString>());
        spMapHeader->insert("Referer", m_strIP + "/html/content.html");
        getInterface(Net)->get(strPlugin, iInfoID, m_strIP + "/" + strUrl, spMapHeader);
    }
}

void CpeVendorHUAWEI::post(const QString &strPlugin, int iInfoID, const QString &strUrl, const QString &strPost)
{
    if (iInfoID == CPE_HUAWEI_USER_POSTRETURN && getInterface(MainUI))
    {
        getInterface(MainUI)->updateMessage("操作已提交，请勿进行其他操作，请稍候...");
    }
    QSharedPointer<QHash<QString, QString>> spMapHeader = QSharedPointer<QHash<QString, QString>>::create(QHash<QString, QString>());
    QString strAllPost = strPost.contains("<request>") ? strPost : "<?xml version=\"1.0\" encoding=\"UTF-8\"?><request>" + strPost + "</request>";
    strAllPost.replace("\r", "");
    strAllPost.replace("\n", "");
    m_iInfoID = iInfoID, m_strUrl = strUrl, m_strPost = strAllPost, m_strPlugin = strPlugin;
    if (m_strToken.isEmpty())   //若没有Token，去拿Token
    {
        get("CpeVendorHUAWEI", CPE_HUAWEI_GETTOKEN, "api/webserver/SesTokInfo");
    }
    else
    {
        postHelper();
    }
}

void CpeVendorHUAWEI::postHelper()
{
    if (getInterface(Net))
    {
        QSharedPointer<QHash<QString, QString>> spMapHeader = QSharedPointer<QHash<QString, QString>>::create(QHash<QString, QString>());
        QString strNewUrl;
        spMapHeader->insert("Referer", m_strIP + "/html/content.html");
        strNewUrl = m_strIP + "/" + m_strUrl;
        spMapHeader->insert("__RequestVerificationToken", m_strToken);
        m_strToken.clear();
        getInterface(Net)->post(m_strPlugin, m_iInfoID, strNewUrl, m_strPost, spMapHeader);
    }
}

void CpeVendorHUAWEI::status(const QString &str)
{
    if (getInterface(Util) == nullptr)
    {
        return;
    }
    QString strT = getInterface(Util)->getXml(str, "BatteryPercent"); //显示电池百分比
    if (strT != "")
    {
        ui->barBattery->setVisible(true);
        ui->barBattery->setCur(strT);
        if (getInterface(Util)->getXml(str, "usbup") == "1")
        {
            ui->lblCharging->setVisible(true);
        }
        else if (getInterface(Util)->getXml(str, "BatteryStatus") == "1")
        {
            ui->lblCharging->setVisible(true);
        }
        else
        {
            ui->lblCharging->setVisible(false);
        }
    }
    else
    {
        ui->barBattery->setVisible(false);
        ui->lblCharging->setVisible(true);//CPE类设备永久显示充电符号
    }
    m_strConnectType = getInterface(Util)->getXml(str, "ConnectionStatus");
    if (m_strConnectType != "" && m_strConnectType != "901")
    {
        ui->lblConnect->setText(connectMode(m_strConnectType.toInt()));
    }
    if (getInterface(Util)->getXml(str, "EndcStatus") == "1")
    {
        m_bNrPoint = true;
    }
    else
    {
        m_bNrPoint = false;
    }
    if (getInterface(Util)->getXml(str, "speedLimitStatus") == "1") //判断卡是否被限速
    {
        ui->lblSpeedLimit->setVisible(true);
    }
    else
    {
        ui->lblSpeedLimit->setVisible(false);
    }
    m_hwNetTypeEx = getInterface(Util)->getXml(str, "CurrentNetworkTypeEx");
    strT = NetTypetoStr(m_hwNetTypeEx);
    if (strT.indexOf("LTE") == -1)
    {
        ui->lblNetType->setText(strT);
    }
}

void CpeVendorHUAWEI::plmn(const QString &str)
{
    if (getInterface(Util))
    {
        QString fullName = getInterface(Util)->getXml(str, "FullName");
        getInterface(Util)->opeartorRegular(fullName);
        ui->lblOperatorName->setText(fullName);
        m_hwNetType = getInterface(Util)->getXml(str, "Rat");
    }
}

void CpeVendorHUAWEI::traffic(const QString &str)
{
    if (getInterface(Util) == nullptr)
    {
        return;
    }
    ui->txtCurTime->setText(getInterface(Util)->timeConv(getInterface(Util)->getXml(str, "CurrentConnectTime")));
    ui->txtTotalTime->setText(getInterface(Util)->timeConv(getInterface(Util)->getXml(str, "TotalConnectTime")));
    ui->txtCurUL->setText(getInterface(Util)->byteConv(getInterface(Util)->getXml(str, "CurrentUpload"), false, true));
    ui->txtCurDL->setText(getInterface(Util)->byteConv(getInterface(Util)->getXml(str, "CurrentDownload"), false, true));
    ui->txtDLRate->setText(getInterface(Util)->byteConv(getInterface(Util)->getXml(str, "CurrentDownloadRate"), true, true));
    ui->txtULRate->setText(getInterface(Util)->byteConv(getInterface(Util)->getXml(str, "CurrentUploadRate"), true, true));
    if (m_strConnectType == "901")
    {
        QString strTemp;
        if (getInterface(Util)->getXml(str, "CurrentUploadRate") == "0")
        {
            strTemp += "<span style=\" color:#A0A0A0;\">↑</span>";
        }
        else
        {
            strTemp += "<span style=\" color:#000000;\">↑</span>";
        }
        if (getInterface(Util)->getXml(str, "CurrentDownloadRate") == "0")
        {
            strTemp += "<span style=\" color:#A0A0A0;\">↓</span>";
        }
        else
        {
            strTemp += "<span style=\" color:#000000;\">↓</span>";
        }
        ui->lblConnect->setText(strTemp);
    }
}

void CpeVendorHUAWEI::signal(const QString &str)
{
    if (getInterface(Util) == nullptr)
    {
        return;
    }
    QString strT;
    if (m_hwNetType == "0")   //2G
    {
        show2G();
        if (m_hwLac == "")
        {
            m_hwLac = getInterface(Util)->getXml(str, "lac");
        }
        if (m_hwCid == "")
        {
            m_hwCid = getInterface(Util)->getXml(str, "cell_id");
        }
        m_hwCid = QString::number(m_hwCid.toUInt());
        ui->txtTAC->setText(m_hwLac);
        ui->txtCID->setText(m_hwCid);
        ui->barRSRP->setCur(getInterface(Util)->getXml(str, "rxlev").remove("dBm"));
        ui->txtARFCN->setText(getInterface(Util)->getXml(str, "arfcn"));
        int nBSIC = getInterface(Util)->getXml(str, "bsic").toUInt(nullptr, 16);
        nBSIC = (nBSIC / 8) * 10 + nBSIC % 8;
        ui->txtPCI->setText(QString::number(nBSIC));
        ui->barPUSCH->setCur(getInterface(Util)->strMid(getInterface(Util)->getXml(str, "txpower"), "stxpwr:", "dBm"));
    }
    if (m_hwNetType == "2" || m_hwNetType == "5")   //3G
    {
        show3G();
        ui->txtPCI->setText(getInterface(Util)->getXml(str, "sc"));
        if (m_hwLac == "")
        {
            m_hwLac = getInterface(Util)->getXml(str, "lac");
        }
        if (m_hwCid == "")
        {
            m_hwCid = getInterface(Util)->getXml(str, "cell_id");
        }
        m_hwCid = QString::number(m_hwCid.toUInt() / 65536) + "/" + QString::number(m_hwCid.toUInt() % 65536);
        ui->txtTAC->setText(m_hwLac);
        ui->txtCID->setText(m_hwCid);
        ui->txtARFCN->setText(getInterface(Util)->getXml(str, "wdlfreq"));
        ui->barRSRP->setCur(getInterface(Util)->getXml(str, "rscp").remove("dBm"));
        ui->barRSRQ->setCur(getInterface(Util)->getXml(str, "ecio").remove("dB"));
        ui->barPUSCH->setCur(getInterface(Util)->strMid(getInterface(Util)->getXml(str, "txpower"), "stxpwr:", "dBm"));
    }
    if (m_hwNetType == "7")   //LTE or NSA
    {
        show4G();
        ui->barRSRP->setCur(getInterface(Util)->getXml(str, "rsrp").remove("dBm"));
        ui->barRSRQ->setCur(getInterface(Util)->getXml(str, "rsrq").remove("dB"));
        ui->barSINR->setCur(getInterface(Util)->getXml(str, "sinr").remove("dB"));
        ui->txtPCI->setText(getInterface(Util)->getXml(str, "pci"));
        if (m_hwLac == "")
        {
            m_hwLac = getInterface(Util)->getXml(str, "tac");
        }
        if (m_hwCid == "")
        {
            m_hwCid = getInterface(Util)->getXml(str, "cell_id");
        }
        m_hwCid = QString::number(m_hwCid.toUInt() / 256) + "/" + QString::number(m_hwCid.toUInt() % 256);
        ui->txtTAC->setText(m_hwLac);
        ui->txtCID->setText(m_hwCid);
        strT = getInterface(Util)->getXml(str, "ulbandwidth").remove("MHz");
        strT.replace("1400KHz", "1.4");
        ui->barULBW->setCur(strT);
        strT = getInterface(Util)->getXml(str, "dlbandwidth").remove("MHz");
        strT.replace("1400KHz", "1.4");
        ui->barDLBW->setCur(strT);
        ui->txtARFCN->setText(getInterface(Util)->strMid(getInterface(Util)->getXml(str, "earfcn"), "DL:", " UL:"));
        if (getInterface(Util)->getXml(str, "band") != "")
        {
            ui->txtBand->setText("B" + getInterface(Util)->getXml(str, "band"));
        }
        ui->barPUSCH->setCur(getInterface(Util)->strMid(getInterface(Util)->getXml(str, "txpower"), "PPusch:", "dBm PPucch:"));
        ui->barPUCCH->setCur(getInterface(Util)->strMid(getInterface(Util)->getXml(str, "txpower"), "PPucch:", "dBm PSrs:"));
        ui->barULMCS->setCur(getInterface(Util)->strMid(str, "<ul_mcs>mcsUpCarrier1:", "</ul_mcs>"));
        ui->barDLMCS->setCur(getInterface(Util)->strMid(str, "mcsDownCarrier1Code0:", " mcsDownCarrier1Code1:"));
        strT = getInterface(Util)->getXml(str, "cqi0");
        if (strT == "127" || strT == "32639")
        {
            strT = "N/A";
        }
        ui->barCQI->setCur(strT);
        ui->txtTM->setText(getInterface(Util)->getXml(str, "transmode"));
        if (getInterface(Util)->getXml(str, "nrrsrp") != "" && getInterface(Util)->getXml(str, "nrrsrp") != "N/A")
        {
            showNR();
            showLayout(ui->layoutNRARFCNPCI);
            ui->barNRRSRP->setCur(getInterface(Util)->getXml(str, "nrrsrp").remove("dBm"));
            ui->barNRRSRQ->setCur(getInterface(Util)->getXml(str, "nrrsrq").remove("dB"));
            ui->barNRSINR->setCur(getInterface(Util)->getXml(str, "nrsinr").remove("dB"));
            ui->barNRPUSCH->setCur(getInterface(Util)->strMid(getInterface(Util)->getXml(str, "nrtxpower"), "PPusch:", "dBm PPucch:"));
            ui->barNRPUCCH->setCur(getInterface(Util)->strMid(getInterface(Util)->getXml(str, "nrtxpower"), "PPucch:", "dBm PSrs:"));
            ui->barNRULMCS->setCur(getInterface(Util)->strMid(str, "<nrulmcs>NRmcsUpCarrier1:", "</nrulmcs>"));
            ui->barNRDLMCS->setCur(getInterface(Util)->strMid(str, "NRmcsDownCarrier1Code0:", " NRmcsDownCarrier1Code1:"));
            ui->barNRULBW->setCur(getInterface(Util)->getXml(str, "nrulbandwidth").remove("MHz"));
            ui->barNRDLBW->setCur(getInterface(Util)->getXml(str, "nrdlbandwidth").remove("MHz"));
            ui->txtNRARFCN->setText(getInterface(Util)->getXml(str, "nrearfcn"));
            ui->lblNetType->setText("5G NSA");
        }
        else
        {
            hideNR();
            if (m_bNrPoint)
            {
                ui->lblNetType->setText("NSA未激活");
            }
            else
            {
                ui->lblNetType->setText(NetTypetoStr(m_hwNetTypeEx));
            }
        }
    }
    if (m_hwNetType == "12" || m_hwNetTypeEx == "111")   //SA
    {
        showSA();
        if (m_hwLac == "")
        {
            m_hwLac = getInterface(Util)->getXml(str, "lac");
        }
        if (m_hwCid == "")
        {
            m_hwLac = getInterface(Util)->getXml(str, "cell_id");
        }
        m_hwCid = QString::number(m_hwCid.toULongLong() / 4096) + "/" + QString::number(m_hwCid.toULongLong() % 4096);
        ui->txtTAC->setText(m_hwLac);
        ui->txtCID->setText(m_hwCid);
        QString strPCI = getInterface(Util)->getXml(str, "pci");
        if (strPCI.contains("0x"))
        {
            ui->txtPCI->setText(QString::number(strPCI.toUInt(nullptr, 16)));
        }
        else
        {
            ui->txtPCI->setText(strPCI);
        }
        ui->barNRRSRP->setCur(getInterface(Util)->getXml(str, "nrrsrp").remove("dBm"));
        ui->barNRRSRQ->setCur(getInterface(Util)->getXml(str, "nrrsrq").remove("dB"));
        ui->barNRSINR->setCur(getInterface(Util)->getXml(str, "nrsinr").remove("dB"));
        ui->barNRPUSCH->setCur(getInterface(Util)->strMid(getInterface(Util)->getXml(str, "nrtxpower"), "PPusch:", "dBm PPucch:"));
        ui->barNRPUCCH->setCur(getInterface(Util)->strMid(getInterface(Util)->getXml(str, "nrtxpower"), "PPucch:", "dBm PSrs:"));
        ui->barNRULMCS->setCur(getInterface(Util)->strMid(str, "<nrulmcs>NRmcsUpCarrier1:", "</nrulmcs>"));
        ui->barNRDLMCS->setCur(getInterface(Util)->strMid(str, "NRmcsDownCarrier1Code0:", " NRmcsDownCarrier1Code1:"));
        ui->barNRULBW->setCur(getInterface(Util)->getXml(str, "nrulbandwidth").remove("MHz"));
        ui->barNRDLBW->setCur(getInterface(Util)->getXml(str, "nrdlbandwidth").remove("MHz"));
        QString strARFCN = getInterface(Util)->getXml(str, "nrearfcn");
        strARFCN = getInterface(Util)->strMid(strARFCN, "DL:", " UL:");
        ui->txtARFCN->setText(strARFCN);
        if (getInterface(Util)->getXml(str, "band") != "")
        {
            ui->txtBand->setText("N" + getInterface(Util)->getXml(str, "band"));
        }
    }
}

void CpeVendorHUAWEI::cellInfo(const QString &str)
{
    if (getInterface(Util))
    {
        m_hwLac = getInterface(Util)->getXml(str, "lac");
        m_hwCid = getInterface(Util)->getXml(str, "cellinfo");
        if (m_hwLac != "")
        {
            m_hwLac = QString::number(m_hwLac.toUInt(nullptr, 16));
        }
        if (m_hwCid != "")
        {
            m_hwCid = QString::number(m_hwCid.toULongLong(nullptr, 16));
        }
    }

}

void CpeVendorHUAWEI::totalTraffic(const QString &str)
{
    if (getInterface(Util))
    {
        ui->txtMonthDL->setText(getInterface(Util)->byteConv(getInterface(Util)->getXml(str, "CurrentMonthDownload"), false, true));
        ui->txtMonthUL->setText(getInterface(Util)->byteConv(getInterface(Util)->getXml(str, "CurrentMonthUpload"), false, true));
        ui->lblDayDL->setText("当日流量");
        ui->txtDayDL->setText(getInterface(Util)->byteConv(getInterface(Util)->getXml(str, "CurrentDayUsed"), false, true));
        ui->lblDayUL->setText("当日时间");
        ui->txtDayUL->setText(getInterface(Util)->timeConv(getInterface(Util)->getXml(str, "CurrentDayDuration")));
    }
}

void CpeVendorHUAWEI::refreshOnce()
{
    //刷新一次的调用顺序
    //information->antenna->dataswitch->netmodelist->netmode->status->traffic->plmn->cellinfo->signal->trafficmonth
    get("CpeVendorHUAWEI", CPE_HUAWEI_INFORMATION, "api/device/information");
}

void CpeVendorHUAWEI::unlockBandLock(CpeEmUnlockBandType eType)
{
    QString str3GMask;
    str3GMask = m_hwCGW == "0" ? "0" : "3fffffff";
    QString strPost = "<NetworkMode>00</NetworkMode><NetworkBand>" + str3GMask + "</NetworkBand>";
    strPost += "<LTEBand>7ffffffffffffff</LTEBand>";
    if (m_bNrOption)
    {
        strPost += "<networkOption>2</networkOption>";
    }
    post("CpeVendorHUAWEI", CPE_HUAWEI_USER_POSTRETURN, "api/net/net-mode", strPost);
}

void CpeVendorHUAWEI::setRat(const QString &strRat)
{

}

void CpeVendorHUAWEI::show2G()
{
    ui->lblPCI->setText("BSIC");
    ui->lblARFCN->setText("ARFCN");
    ui->lblRSRP->setText("RxLev");
    ui->lblTAC->setText("LAC");
    ui->lblCID->setText("CID");
    ui->barRSRQ->setCur("N/A");
    ui->barSINR->setCur("N/A");
    ui->barPUCCH->setCur("N/A");
    ui->txtTM->setText("N/A");
    hideLayout(ui->layoutNRARFCNPCI);
    hideNR();
}
void CpeVendorHUAWEI::show3G()
{
    ui->lblPCI->setText("PSC");
    ui->lblARFCN->setText("UARFCN");
    ui->lblRSRP->setText("RSCP");
    ui->lblTAC->setText("LAC");
    ui->lblRSRQ->setText("EC/IO");
    ui->lblCID->setText("CID");
    ui->barSINR->setCur("N/A");
    ui->barPUCCH->setCur("N/A");
    hideLayout(ui->layoutNRARFCNPCI);
    hideNR();
}

void CpeVendorHUAWEI::show4G()
{
    showLayout(ui->layoutDetailInfo);
    showLayout(ui->layoutMainInfo);
    showLayout(ui->layoutSignal);
    ui->lblPCI->setText("PCI");
    ui->lblARFCN->setText("EARFCN");
    ui->lblRSRP->setText("RSRP");
    ui->lblTAC->setText("TAC");
    ui->lblCID->setText("eCellID");
}

void CpeVendorHUAWEI::showNR()
{
    showLayout(ui->layoutNRDetailInfo);
    showLayout(ui->layoutNRSignal);
}
void CpeVendorHUAWEI::hideNR()
{
    hideLayout(ui->layoutNRDetailInfo);
    hideLayout(ui->layoutNRSignal);
    hideLayout(ui->layoutNRARFCNPCI);
}

void CpeVendorHUAWEI::showSA()
{
    ui->lblPCI->setText("NR_PCI");
    ui->lblTAC->setText("TAC");
    ui->lblCID->setText("gCellID");
    showNR();
    hideLayout(ui->layoutSignal);
    hideLayout(ui->layoutDetailInfo);
    hideLayout(ui->layoutNRARFCNPCI);
}

void CpeVendorHUAWEI::hideLayout(QLayout *pLayout)
{
    for (qsizetype i = 0; i < pLayout->count(); ++i)
    {
        QWidget *pWidget = pLayout->itemAt(i)->widget();
        QLayout *pSubLayout = pLayout->itemAt(i)->layout();
        if (pWidget != nullptr)
        {
            if (!pWidget->isVisible())
            {
                return;
            }
            pWidget->hide();
        }
        if (pSubLayout != nullptr)
        {
            hideLayout(pSubLayout);
        }
    }
}

void CpeVendorHUAWEI::showLayout(QLayout *pLayout)
{
    for (qsizetype i = 0; i < pLayout->count(); ++i)
    {
        QWidget *pWidget = pLayout->itemAt(i)->widget();
        QLayout *pSubLayout = pLayout->itemAt(i)->layout();
        if (pWidget != nullptr)
        {
            if (pWidget->isVisible())
            {
                return;
            }
            pWidget->show();
        }
        if (pSubLayout != nullptr)
        {
            showLayout(pSubLayout);
        }
    }
}

QString CpeVendorHUAWEI::NetTypetoStr(const QString &strType)
{
    if (strType == "0")
    {
        return "无服务";
    }
    if (strType == "1")
    {
        return "GSM";
    }
    if (strType == "2")
    {
        return "GPRS";
    }
    if (strType == "3")
    {
        return "EDGE";
    }
    if (strType == "21")
    {
        return "IS95A";
    }
    if (strType == "22")
    {
        return "IS95B";
    }
    if (strType == "23")
    {
        return "CDMA 1x";
    }
    if (strType == "24")
    {
        return "EVDO rev.0";
    }
    if (strType == "25")
    {
        return "EVDO rev.A";
    }
    if (strType == "26")
    {
        return "EVDO rev.B";
    }
    if (strType == "27")
    {
        return "CDMA 1x";
    }
    if (strType == "28")
    {
        return "EVDO rev.0";
    }
    if (strType == "29")
    {
        return "EVDO rev.A";
    }
    if (strType == "30")
    {
        return "EVDO rev.B";
    }
    if (strType == "31")
    {
        return "eHRPD rel.0";
    }
    if (strType == "32")
    {
        return "eHRPD rel.A";
    }
    if (strType == "33")
    {
        return "eHRPD rel.B";
    }
    if (strType == "34")
    {
        return "eHRPD rel.0";
    }
    if (strType == "35")
    {
        return "eHRPD rel.A";
    }
    if (strType == "36")
    {
        return "eHRPD rel.B";
    }
    if (strType == "41")
    {
        return "WCDMA";
    }
    if (strType == "42")
    {
        return "HSDPA";
    }
    if (strType == "43")
    {
        return "HSUPA";
    }
    if (strType == "44")
    {
        return "HSPA";
    }
    if (strType == "45")
    {
        return "HSPA+";
    }
    if (strType == "46")
    {
        return "DC HSPA+";
    }
    if (strType == "61")
    {
        return "TD-SCDMA";
    }
    if (strType == "62")
    {
        return "TD-HSDPA";
    }
    if (strType == "63")
    {
        return "TD-HSUPA";
    }
    if (strType == "64")
    {
        return "TD_HSPA";
    }
    if (strType == "65")
    {
        return "TD_HSPA+";
    }
    if (strType == "81")
    {
        return "802.16E";
    }
    if (strType == "101")
    {
        return "LTE";
    }
    if (strType == "1011")
    {
        return "LTE CA";
    }
    if (strType == "111")
    {
        return "5G SA";
    }
    return "Unknown";
}

QString CpeVendorHUAWEI::connectMode(int nType)
{
    switch (nType)
    {
        case 900:
            return "连接中...";
            break;
        case 901:
            return "已连接";
            break;
        case 902:
            return "已断开";
            break;
        case 903:
            return "断开中...";
            break;
        case 904:
            return "连接失败";
            break;
        case 905:
            return "无服务";
            break;
        case 906:
            return "连接错误";
            break;
        default:
            return QString::number(nType);
    }
}

void CpeVendorHUAWEI::unlockLTECellLock()
{
    post("CpeVendorHUAWEI", CPE_HUAWEI_USER_POSTRETURN, "api/net/lock-freq", "<mode>0</mode><enable>0</enable><freq>0</freq><band>0</band><cellid>0</cellid>");
}

void CpeVendorHUAWEI::unlockNRCellLock()
{
    post("CpeVendorHUAWEI", CPE_HUAWEI_USER_POSTRETURN, "api/net/lock-freq", "<mode>1</mode><enable>0</enable><scstype>1</scstype><freq>0</freq><band>0</band><cellid>0</cellid>");
}

void CpeVendorHUAWEI::on_chkDataSwitch_clicked(bool checked)
{
    QString strSwitch = checked ? "1" : "0";
    post("CpeVendorHUAWEI", CPE_HUAWEI_USER_POSTRETURN, "api/dialup/mobile-dataswitch", "<dataswitch>" + strSwitch + "</dataswitch>");
}


void CpeVendorHUAWEI::on_chk5GAntenna_clicked(bool checked)
{
    QString strSwitch = checked ? "1" : "0";
    post("CpeVendorHUAWEI", CPE_HUAWEI_USER_POSTRETURN, "api/device/antenna_ext_td_switch", "<extantennaswitch>" + strSwitch + "</extantennaswitch>");
}


void CpeVendorHUAWEI::on_rdoInternal_clicked()
{
    post("CpeVendorHUAWEI", CPE_HUAWEI_USER_POSTRETURN, "api/device/antenna_set_type", "<antennasettype>2</antennasettype>");
}


void CpeVendorHUAWEI::on_rdoMixed_clicked()
{
    post("CpeVendorHUAWEI", CPE_HUAWEI_USER_POSTRETURN, "api/device/antenna_set_type", "<antennasettype>3</antennasettype>");
}


void CpeVendorHUAWEI::on_rdoAuto_clicked()
{
    post("CpeVendorHUAWEI", CPE_HUAWEI_USER_POSTRETURN, "api/device/antenna_set_type", "<antennasettype>0</antennasettype>");
}


void CpeVendorHUAWEI::on_rdoExternal_clicked()
{
    post("CpeVendorHUAWEI", CPE_HUAWEI_USER_POSTRETURN, "api/device/antenna_set_type", "<antennasettype>1</antennasettype>");
}

